#pragma once
#include <iostream>
#include <string>
#include <cstring>
#include <unistd.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
void deal(std::string &data, int sock)
{
    // 反序列化
    std::string respon;
    int x = 0;
    int y = 0;
    char op = '\0';
    int lpos = data.find(" ");
    int rpos = data.rfind(" ");
    // std::cout<<lpos<<" "<<rpos<<std::endl;
    if (lpos != std::string::npos && rpos != std::string::npos)
    {
        x = atoi(data.substr(lpos - 1).c_str());
        op = *data.substr(lpos + 1, rpos - 1).c_str();
        y = atoi(data.substr(rpos + 1).c_str());
        // std::cout<<x<<" "<<y<<" "<<op<<std::endl;
    }
    else
    {
        if (data == std::string())
            return;
        else
        {
            std::cout << "式子格式错误" << std::endl;
            exit(4);
        }
    }
    // 处理
    switch (op)
    {
    case '+':
        respon = std::to_string(x + y);
        break;
    case '-':
        respon = std::to_string(x - y);
        break;
    case '*':
        respon = std::to_string(x * y);
        break;
    case '/':
        respon = std::to_string(x / y);
        break;
    default:
        std::cout << "计算格式错误" << std::endl;
        break;
    }

    // 关闭链接
    send(sock, respon.c_str(), respon.size(), 0);
    close(sock);
}